<template>
    <div id="line-chart" :class="className" :style="{ width: width, height: height }"></div>
</template>
<script>
import * as echarts from 'echarts'
require('echarts/theme/blue')
import resize from './mixins/resize'
export default {
    name: 'lineChart',
    mixins: [resize],
    props: {
        className: {
            type: String,
            default: 'chart'
        },
        width: {
            type: String,
            default: '100%'
        },
        height: {
            type: String,
            default: '400px'
        }
    },
    data() {
        return {
            chart: null
        }
    },
    mounted() {
        this.$nextTick(() => {
            this.initChart()
        })
    },
    beforeDestroy() {
        if (!this.chart) {
            return
        }
        this.chart.dispose()
        this.chart = null
    },
    methods: {
        async initChart() {
            this.chart = echarts.init(this.$el, 'blue')
            const options = {
                xAxis: {
                    type: 'category',
                    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        data: [820, 932, 901, 934, 1290, 1330, 1320],
                        type: 'line',
                        smooth: true
                    }
                ]
            }
            this.chart.setOption(options)
        }
    }
}
</script>
<style scoped lang='scss'></style>